#include "main.h"
#include "mdsh.h"
#include "solog.h"

static void _syslog(char *str)
{
    mshell_printf("\r\n");

    SERIAL_t serial = (SERIAL_t)mshell_dev();

    char mode = 0;
    char *parameter = str;

    str = parameter;
    parameter = strchr(str,'-');
    if(parameter == NULL)
    {
        mshell_printf("parameter error\r\n");
        return;
    }
    parameter++;
    mode = *parameter;
    if(mode == 'o')
    {
        solog_mode(SOLOG_MODE_CONSOLE);
        uint8_t b = 0;
        while(b != CTRLC)
        {
            if(serial->readable() > 0)
            {
                serial->read(0,&b,1,NULL);
            }
        }
        solog_mode(SOLOG_MODE_DEFAULT);
    }
    else if(mode == 's')
    {
        solog_mode(SOLOG_MODE_FLASH);
    }
    else if(mode == 'n')
    {
        solog_mode(SOLOG_MODE_DEFAULT);
    }
    else if(mode == 'c')
    {

    }
    else if(mode == 'i')
    {

    }
}

static shell_table _mdsh_syslog_table[] =
{
    {"syslog",  _syslog,    "\r\nsyslog\r\n"},
};

static void _mdsh_syslog_init(void)
{
    // mshell_printf("%s start\r\n",__FUNCTION__);
    mdsh_put(_mdsh_syslog_table, sizeof(_mdsh_syslog_table)/sizeof(shell_table));
}
MDSH_CMD_INIT(_mdsh_syslog_init);
